package com.ruoyi.finance.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.finance.domain.TCwCztxApply;
import com.ruoyi.finance.service.ITCwCztxApplyService;
import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商户充值提现申请Controller
 *
 * @author wish
 * @date 2021-06-23
 */
@RestController
@RequestMapping("/apply")
public class TCwCztxApplyController extends BaseController
{
    @Autowired
    private ITCwCztxApplyService tCwCztxApplyService;

    @Autowired
    RemoteFileService remoteFileService;

    @PostMapping("/upload")
    public SysFile upload(MultipartFile file){
        System.out.println("!111111111111111111111111111111111");
        return remoteFileService.upload(file).getData();
    }

    @PreAuthorize(hasPermi = "finance:apply:findAll")
    @GetMapping("/findAll")
    public TableDataInfo findAll(TCwCztxApply tCwCztxApply)
    {
        startPage();
        List<TCwCztxApply> findAll = tCwCztxApplyService.findAll(tCwCztxApply);
        return getDataTable(findAll);
    }

    /**
     * 查询商户充值提现申请列表
     */
    @PreAuthorize(hasPermi = "finance:apply:list")
    @GetMapping("/list")
    public TableDataInfo list(TCwCztxApply tCwCztxApply)
    {
        startPage();
        List<TCwCztxApply> list = tCwCztxApplyService.selectTCwCztxApplyList(tCwCztxApply);
        return getDataTable(list);
    }

    /**
     * 导出商户充值提现申请列表
     */
    @PreAuthorize(hasPermi = "finance:apply:export")
    @Log(title = "商户充值提现申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCwCztxApply tCwCztxApply) throws IOException
    {
        List<TCwCztxApply> list = tCwCztxApplyService.selectTCwCztxApplyList(tCwCztxApply);
        ExcelUtil<TCwCztxApply> util = new ExcelUtil<TCwCztxApply>(TCwCztxApply.class);
        util.exportExcel(response, list, "商户充值提现申请数据");
    }

    /**
     * 获取商户充值提现申请详细信息
     */
    @PreAuthorize(hasPermi = "finance:apply:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tCwCztxApplyService.selectTCwCztxApplyById(id));
    }

    /**
     * 新增商户充值提现申请
     */
    @PreAuthorize(hasPermi = "finance:apply:add")
    @Log(title = "商户充值提现申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCwCztxApply tCwCztxApply)
    {
        return toAjax(tCwCztxApplyService.insertTCwCztxApply(tCwCztxApply));
    }

    /**
     * 充值提现申请
     */
    @PreAuthorize(hasPermi = "finance:apply:edit")
    @Log(title = "商户充值提现申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCwCztxApply tCwCztxApply)
    {
        return toAjax(tCwCztxApplyService.updateTCwCztxApply(tCwCztxApply));
    }

    /**
     * 删除商户充值提现申请
     */
    @PreAuthorize(hasPermi = "finance:apply:remove")
    @Log(title = "商户充值提现申请", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCwCztxApplyService.deleteTCwCztxApplyByIds(ids));
    }
}
